package com.hyfd.service.mp;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hyfd.common.utils.StringUtil;
import com.hyfd.common.utils.XiChengAESUtils;
import com.hyfd.common.utils.XmlUtils;
import com.hyfd.dao.mp.OrderDao;
import com.hyfd.dao.mp.ProviderPhysicalChannelDao;
import com.hyfd.rabbitMq.RabbitMqProducer;
import com.hyfd.rabbitMq.SerializeUtil;
import com.hyfd.service.BaseService;

@Service
public class CallBackForProviderSer extends BaseService
{
    
    public Logger log = Logger.getLogger(this.getClass());
    
    @Autowired
    RabbitMqProducer mqProducer;
    
    @Autowired
    ProviderPhysicalChannelDao providerPhysicalChannelDao;
    
    @Autowired
    OrderDao orderDao;
    
    /**
     * 好亚飞达话费状态回调
     * 
     * @author lks 2016年12月13日上午11:20:33
     * @param request
     * @param response
     * @return
     */
    public String statusBackForHyfdBill(HttpServletRequest request, HttpServletResponse response)
    {
        Map<String, Object> param = getMaps(request);
        String orderId = (String)param.get("orderId");// 获取订单id
        String customerOrderId = (String)param.get("customerOrderId");// 获取客户订单号
        String phoneNo = (String)param.get("phoneNo");// 获取手机号
        String spec = (String)param.get("spec");// 金额，以分为单位
        String scope = (String)param.get("scope");// 应用范围
        String status = (String)param.get("status");// 状态
        String signature = (String)param.get("signature");// 签名
        // TODO 签名验证
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderId", customerOrderId);
        map.put("providerOrderId", orderId);
        if (status.equals("success"))
        {
            map.put("status", 1);
        }
        else if (status.equals("fail"))
        {
            map.put("status", 0);
        }
        if (map.containsKey("status"))
        {
            mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        }
        return "success";
    }
    
    /**
     * 投石流量回调
     * 
     * @author lks 2017年2月21日上午11:35:19
     * @param request
     * @param response
     * @return
     */
    public String statusBackForTouShi(HttpServletRequest request, HttpServletResponse response)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> param = getMaps(request);
        String userId = param.get("userid") + "";// 用户名
        String orderid = param.get("orderid") + "";// 平台订单号
        String state = param.get("state") + "";// 订单状态
        String account = param.get("account") + "";//
        String userkey = (String)param.get("userkey");// 加密信息
        Map<String, Object> order = orderDao.selectByOrderId(orderid);
        if (order == null)
        {
            log.error("投石回调的数据查询为空，订单号为" + orderid);
            return "NOT OK";
        }
        String status = order.get("status") + "";
        if (!status.equals("1"))
        {
            log.error("投石重复回调，订单号为" + orderid);
            return "OK";
        }
        map.put("orderId", orderid);
        if (state.equals("1"))
        {// 充值成功
            map.put("status", 1);
        }
        else if (state.equals("2"))
        {// 充值失败
            map.put("status", 0);
        }
        if (map.containsKey("status"))
        {
            mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        }
        return "OK";
    }
    
    /**
     * 尚通回调
     * 
     * @author lks 2017年3月9日下午6:45:55
     * @param request
     * @param response
     * @return
     */
    public String statusBackForShangTong(HttpServletRequest request, HttpServletResponse response)
    {
        String paramJsonStr = getRequestContext(request);
        log.error("尚通回调，获取的JSON数据为" + paramJsonStr);
        JSONObject paramJson = JSONObject.parseObject(paramJsonStr);// 格式化为json
        String respCode = paramJson.getString("respCode") + "";// 充值状态
        String respMsg = paramJson.getString("respMsg") + "";// 充值消息
        String orderno_ID = paramJson.getString("orderno_ID") + "";// 订单号
        String orderID = paramJson.getString("orderID") + "";//
        String phoneNo = paramJson.getString("phoneNo") + "";// 手机号
        log.error("尚通回调，获取到的数据为 respCode=" + respCode + "|respMsg=" + respMsg + "|orderno_ID=" + orderno_ID
            + "|orderID=" + orderID + "|phoneNo=" + phoneNo);
        if (StringUtils.isEmpty(respCode) || StringUtils.isEmpty(respMsg) || StringUtils.isEmpty(orderno_ID)
            || StringUtils.isEmpty(orderID) || StringUtils.isEmpty(phoneNo))
        {
            return "fail";
        }
        
        Map<String, Object> order = orderDao.selectByOrderId(orderno_ID);// 查询订单
        if (order == null)
        {
            return "fail";
        }
        if ("1".equals(order.get("status")))
        {
            return "fail";
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderId", orderno_ID);
        map.put("providerOrderId", orderID);
        map.put("resultCode", respCode + ":" + respMsg);
        if (respCode.equals("0002"))
        {// 充值成功
            map.put("status", "1");
        }
        else if (respCode.equals("0003"))
        {// 充值失败
            map.put("status", "0");
        }
        if (map.containsKey("status"))
        {
            mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        }
        return "success";
    }
    
    /**
     * 博亚回调
     * 
     * @author lks 2017年3月29日下午3:04:31
     * @param request
     * @param response
     * @return
     */
    public String statusBackForBoYa(HttpServletRequest request, HttpServletResponse response)
    {
        Map<String, Object> paramMap = getMaps(request);
        String outTradeNo = paramMap.get("outTradeNo") + "";// 平台订单号
        String sysOrderId = paramMap.get("sysOrderId") + "";// 上家订单号
        String resultCode = paramMap.get("resultCode") + "";// 充值状态
        String resultDesc = paramMap.get("resultDesc") + "";
        if (outTradeNo == null || sysOrderId == null || resultCode == null)
        {
            log.error("博亚回调参数不全");
            return "{\"code\": \"400\", \"msg\": \"参数为空\"}";
        }
        Map<String, Object> order = orderDao.selectByOrderId(outTradeNo);// 查询订单
        if (order == null)
        {
            log.error("博亚回调的订单号未找到订单" + outTradeNo + "||" + sysOrderId);
            return "{\"code\": \"400\", \"msg\": \"参数不正确\"}";
        }
        if (!"1".equals(order.get("status")))
        {
            log.error("平台订单号" + outTradeNo + "重复回调不处理");
            return "{\"code\": \"400\", \"msg\": \"重复回调\"}";
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderId", outTradeNo);
        map.put("providerOrderId", sysOrderId);
        map.put("resultCode", resultCode + ":" + resultDesc);
        if (resultCode.equals("200"))
        {
            map.put("status", "1");
        }
        else
        {
            map.put("status", "0");
        }
        if (map.containsKey("status"))
        {
            mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        }
        return "{\"code\": \"200\", \"msg\": \"success\"}";
    }
    
   
    
    /**
     * 美科回调
     * 
     * @author lks 2017年3月29日下午3:13:57
     * @param request
     * @param response
     * @return
     */
    public String statusBackForMeiKe(HttpServletRequest request, HttpServletResponse response)
    {
        String jsonStr = getRequestContext(request);
        log.error("美科回调开始，回调参数为" + jsonStr);
        JSONObject json = JSONObject.parseObject(jsonStr);
        JSONArray jsonArr = json.getJSONArray("reports");
        for (int i = 0, size = jsonArr.size(); i < size; i++)
        {
            
        }
        return "1";
    }
    
    /**
     * @Title:statusBackBoLuoMi
     * @Description:菠萝蜜回调 TODO(这里用一句话描述这个方法的作用)
     * @author CXJ
     * @date 2017年7月13日 下午2:42:31
     * @param @param request
     * @param @param response
     * @param @return
     * @return String 返回类型
     * @throws
     */
    public String statusBackBoLuoMi(HttpServletRequest request, HttpServletResponse response)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> param = getMaps(request);
        String providerOrderId = param.get("oid") + "";// 上家订单号
        String satus = param.get("satus") + "";// 订单状态
        
        Map<String, Object> order = orderDao.selectByProviderOrderId(providerOrderId);
        if (order == null)
        {
            log.error("菠萝蜜回调的数据查询为空，上家订单号为" + providerOrderId);
            return "error";
        }
        String orderid = order.get("orderId") + "";
        String status = order.get("status") + "";
        if (!status.equals("1"))
        {
            log.error("菠萝蜜重复回调，订单号为" + orderid);
            return "success";
        }
        map.put("orderId", orderid);
        if (satus.equals("0"))
        {// 充值成功
            map.put("status", 1);
        }
        else if (satus.equals("1"))
        {// 充值失败
            map.put("status", 0);
        }
        if (map.containsKey("status"))
        {
            mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        }
        return "success";
    }
    
    /**
     * 乐免回调
     * 
     * @author lks 2017年4月1日下午2:21:19
     * @param request
     * @param response
     * @return
     */
    public String statusBackForLeMian(HttpServletRequest request, HttpServletResponse response)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        String jsonStr = getRequestContext(request);
        if (jsonStr.equals("") || jsonStr == null)
        {
            return "error";
        }
        log.error("乐免回调，回调参数为" + jsonStr);
        JSONArray jsonArr = JSONObject.parseArray(jsonStr);
        for (int i = 0, size = jsonArr.size(); i < size; i++)
        {
            JSONObject json = jsonArr.getJSONObject(i);
            String upids = json.getString("msgid");// 上家订单号
            String status = json.getString("status");// 回调状态
            if (upids.equals("") || upids == null || status.equals("") || status == null)
            {
                log.error("乐免回调部分参数为空");
                return "error";
            }
            Map<String, Object> order = orderDao.selectByProviderOrderId(upids);
            if (order == null)
            {
                log.error("乐免回调的上家订单号为" + upids + "的订单为空");
                return "error";
            }
            String orderStatus = order.get("status") + "";
            if (!orderStatus.equals("1"))
            {
                log.error("乐免上家订单号" + upids + "重复回调不处理");
                return "error";
            }
            String orderId = order.get("orderId") + "";
            map.put("orderId", orderId);
            String message = "";
            if (status.equals("00000"))
            {// 充值成功
                message = "充值成功";
                map.put("status", 1);
            }
            else
            {// 充值失败
                message = "充值失败";
                map.put("status", 0);
            }
            map.put("resultCode", status + ":" + message);
            if (map.containsKey("status"))
            {
                mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
            }
        }
        return "1";
    }
    
    /**
     * 云旭状态回调接口
     * 
     * @author lks 2017年6月12日下午3:52:08
     * @param request
     * @param response
     * @return
     */
    public String statusBackForYunXu(HttpServletRequest request, HttpServletResponse response)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        JSONObject json = new JSONObject();
        String orderId = request.getParameter("orderid");
        String code = request.getParameter("code");
        String msg = request.getParameter("msg");
        String timestamp = request.getParameter("timestamp");
        String sign = request.getParameter("sign");
        log.error("云旭回调参数为orderId=" + orderId + "|code=" + code + "|msg=" + msg + "|timestamp=" + timestamp + "|sign="
            + sign);
        if (orderId.equals("") || code.equals("") || msg.equals("") || timestamp.equals("") || sign.equals(""))
        {
            log.error("云旭回调的参数有空值");
            json.put("code", "999999");
        }
        else
        {
            Map<String, Object> order = orderDao.selectByOrderId(orderId);// 根据平台订单号查询订单
            if (order == null)
            {
                log.error("云旭回调的参数orderId=" + orderId + "，查不到订单");
                json.put("code", "999999");
            }
            else
            {
                map.put("orderId", orderId);
                if (order.get("status") == null || order.get("status").equals(""))
                {
                    log.error("云旭回调的参数orderId=" + orderId + "，查不到订单状态");
                    json.put("code", "999999");
                }
                else
                {
                    String status = order.get("status") + "";
                    if (!status.equals("1"))
                    {
                        log.error("云旭回调的参数orderId=" + orderId + "，重复回调不处理");
                        json.put("code", "999999");
                    }
                    else
                    {
                        if (code.equals("111111"))
                        {
                            map.put("status", "1");
                        }
                        else if (code.equals("999999"))
                        {
                            map.put("status", "0");
                        }
                        else
                        {
                            map.put("status", "-1");
                        }
                    }
                }
            }
        }
        map.put("resultCode", code + ":" + msg);
        if (map.containsKey("status"))
        {
            mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        }
        return json.toJSONString();
    }
    
    public String statusBackForXiCheng(HttpServletRequest request, HttpServletResponse response)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        JSONObject json = new JSONObject();
        String jsonStr = getRequestContext(request);
        JSONObject js = JSON.parseObject(jsonStr);
        String partyId = js.getString("partyId") + "";
        String data = js.getString("data") + "";
        String time = js.getString("time") + "";
        String sign = js.getString("sign") + "";
        log.error("西城回调参数为partyId=" + partyId + "|partyId=" + partyId + "|data=" + data + "|time=" + time + "|sign="
            + sign);
        if (partyId.equals("") || data.equals("") || time.equals("") || sign.equals(""))
        {
            log.error("西城回调的参数有空值");
            json.put("status", "0");
            json.put("resultCode", "50001");
            json.put("resultDesc", "请求失败,非法请求参数");
            return json.toJSONString();
        }
        else
        {
            try
            {
                Map<String, Object> channel = providerPhysicalChannelDao.selectByPrimaryKey("0000000075");
                String defaultParameter = (String)channel.get("default_parameter");// 默认参数
                Map<String, String> paramMap = XmlUtils.readXmlToMap(defaultParameter);
                String securitKey = paramMap.get("securitKey");// 拿到加密key
                String decryptData = XiChengAESUtils.decrypt(data, securitKey);
                JSONArray dataArr = JSON.parseArray(decryptData);
                for (int i = 0, size = dataArr.size(); i < size; i++)
                {
                    JSONObject jsonObj = dataArr.getJSONObject(i);
                    String orderId = jsonObj.getString("orderId");
                    String callBackStatus = jsonObj.getString("status");
                    String resultCode = jsonObj.getString("resultCode");
                    String resultDesc = jsonObj.getString("resultDesc");
                    Map<String, Object> order = orderDao.selectByOrderId(orderId);// 根据平台订单号查询订单
                    if (order == null)
                    {
                        log.error("西城回调的参数orderId=" + orderId + "，查不到订单");
                        json.put("status", "0");
                        json.put("resultCode", "11009");
                        json.put("resultDesc", "请求失败,未找到匹配的订单");
                        return json.toJSONString();
                    }
                    else
                    {
                        map.put("orderId", orderId);
                        if (order.get("status") == null || order.get("status").equals(""))
                        {
                            log.error("西城回调的参数orderId=" + orderId + "，查不到订单状态");
                            json.put("status", "0");
                            json.put("resultCode", "11009");
                            json.put("resultDesc", "请求失败,未找到匹配的订单");
                            return json.toJSONString();
                        }
                        else
                        {
                            String status = order.get("status") + "";
                            if (status.equals("1"))
                            {
                                if ("1".equals(callBackStatus))
                                {
                                    map.put("status", "1");
                                }
                                else if ("0".equals(callBackStatus))
                                {
                                    map.put("status", "0");
                                }
                                else
                                {
                                    map.put("status", "-1");
                                }
                                map.put("resultCode", resultCode + ":" + resultDesc);
                                if (map.containsKey("status"))
                                {
                                    mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey,
                                        SerializeUtil.getStrFromObj(map));
                                }
                            }
                        }
                    }
                    
                }
            }
            catch (Exception e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
        }
        json.put("status", "1");
        json.put("resultCode", "00000");
        json.put("resultDesc", "请求成功");
        return json.toJSONString();
    }
    
    /**
     * 获取request中的数据
     * 
     * @author lks 2017年4月1日下午2:48:15
     * @param request
     * @return
     */
    public static String getRequestContext(HttpServletRequest request)
    {
        String str = "";
        try
        {
            StringBuilder sb = new StringBuilder();
            InputStream is = request.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String line = "";
            while ((line = br.readLine()) != null)
            {
                sb.append(line);
            }
            str = sb.toString();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
    
    /**
     * @Title:statusBackDHSanTong
     * @Description: TODO(这里用一句话描述这个方法的作用)
     * @author CXJ
     * @date 2017年6月28日 下午3:13:35
     * @param @param request
     * @param @return
     * @return String 返回类型
     * @throws
     */
    public String statusBackDHSanTong(HttpServletRequest request, HttpServletResponse response)
    {
        String json = getRequestContext(request);
        JSONObject jObject = JSONObject.parseObject(json);
        String clientOrderId = jObject.getString("clientOrderId");// 订单号
        String mobile = jObject.getString("mobile");// 手机号
        String reportTime = jObject.getString("reportTime");// 状态报告时间
        String callBackTime = jObject.getString("callBackTime");// 回调时间
        String status = jObject.getString("status");// 订购状态
        String errorCode = jObject.getString("errorCode");// 错误码
        String errorDesc = jObject.getString("errorDesc");// 错误描述
        String intervalTime = jObject.getString("intervalTime");
        String clientSubmitTime = jObject.getString("clientSubmitTime");
        String discount = jObject.getString("discount");
        String costMoney = jObject.getString("costMoney");
        String sign = jObject.getString("sign");
        
        if (StringUtils.isEmpty(clientOrderId) || StringUtils.isEmpty(status))
        {
            log.error("大汉三通回调参数不全");
            return "{\"resultCode\": \"1111\", \"resultMsg\": \"参数为空\"}";
        }
        Map<String, Object> order = orderDao.selectByOrderId(clientOrderId);// 查询订单
        if (order == null)
        {
            log.error("大汉三通回调的订单号未找到订单" + clientOrderId);
            return "{\"resultCode\": \"1111\", \"resultMsg\": \"订单号未找到\"}";
        }
        if (!"1".equals(order.get("status")))
        {
            log.error("平台订单号" + clientOrderId + "重复回调不处理");
            return "{\"resultCode\": \"1111\", \"resultMsg\": \"订单号重复回调\"}";
        }
        
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderId", clientOrderId);
        // map.put("providerOrderId", providerOrderId);
        map.put("resultCode", status + ":" + errorDesc);
        
        if (status.equals("0"))
        {
            map.put("status", "1");
        }
        else
        {
            map.put("status", "0");
        }
        mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        
        return "{\"resultCode\": \"0000\", \"resultMsg\": \"处理成功\"}";
    }
    
    /**
     * 潍坊指通回调
     * 
     * @author cxj 2017年3月31日上午9:00
     * @param request
     * @param response
     * @return
     */
    public String statusBackWFZhitong(HttpServletRequest request, HttpServletResponse response)
    {
        Map<String, Object> paramMap = getMaps(request);
        String outTradeNo = paramMap.get("OutTradeNo") + "";
        String status = paramMap.get("Status") + "";
        String reportCode = paramMap.get("ReportCode") + "";
        if (StringUtil.isEmpty(outTradeNo) || StringUtil.isEmpty(status) || StringUtil.isEmpty(reportCode))
        {
            log.error("潍坊指通回调参数不全");
            return "{\"code\": \"400\", \"msg\": \"参数为空\"}";
        }
        Map<String, Object> order = orderDao.selectByOrderId(outTradeNo);// 查询订单
        if (order == null)
        {
            log.error("潍坊指通回调的订单号未找到订单" + outTradeNo);
            return "fail";
        }
        if (!"1".equals(order.get("status")))
        {
            log.error("平台订单号" + outTradeNo + "重复回调不处理");
            return "ok";
        }
//        String providerOrderId = order.get("providerOrderId") + "";
//        
//        if (StringUtil.isEmpty(providerOrderId))
//        {
//            log.error("潍坊指通回调的上家订单号未找到订单");
//            return "fail";
//        }
        
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderId", outTradeNo);
//        map.put("providerOrderId", providerOrderId);
        map.put("resultCode", status + ":" + reportCode);
        
        if (status.equals("4"))
        {
            map.put("status", "1");
        }
        else
        {
            map.put("status", "0");
        }
        mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        return "ok";
    }
    
    /**
     * @Title:statusBackYinTong
     * @Description: 银通流量回调 TODO(这里用一句话描述这个方法的作用)
     * @author CXJ
     * @date 2017年7月11日 下午2:47:34
     * @param @param request
     * @param @param response
     * @param @return
     * @return String 返回类型
     * @throws
     */
    public String statusBackYinTong(HttpServletRequest request, HttpServletResponse response)
    {
        String json = getRequestContext(request);
        JSONObject jObject = JSONObject.parseObject(json);
        int Code = jObject.getIntValue("Code");// 订单号
        String CodeDesc = jObject.getString("CodeDesc");// 手机号
        int OrderId = 0;
        String MerOrderNo = "";
        String OrderStatus = null;
        if ("0000".equals(Code))
        {
            OrderId = jObject.getIntValue("OrderId");// 上家订单号
            MerOrderNo = jObject.getString("MerOrderNo");// 订单号
            int OrderStatusIn = jObject.getIntValue("OrderStatus");// 上家订单号
            OrderStatus = String.valueOf(OrderStatusIn);
            if (StringUtils.isEmpty(MerOrderNo) || StringUtils.isEmpty(OrderStatus))
            {
                log.error("银通回调参数不全");
                return "Code=0";
            }
        }
        else
        {
            return "Code=0";
        }
        
        Map<String, Object> order = orderDao.selectByOrderId(MerOrderNo);// 查询订单
        if (order == null)
        {
            log.error("银通回调的订单号未找到订单" + MerOrderNo);
            return "Code=0";
        }
        if (!"1".equals(order.get("status")))
        {
            log.error("银通平台订单号" + MerOrderNo + "重复回调不处理");
            return "Code=0";
        }
        
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderId", MerOrderNo);
        // map.put("providerOrderId", providerOrderId);
        map.put("resultCode", Code + ":" + CodeDesc);
        
        if (OrderStatus.equals("1"))
        {
            map.put("status", "1");
        }
        else if (OrderStatus.equals("2"))
        {
            map.put("status", "0");
        }
        else
        {
            return "Code=1";
        }
        mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        
        return "Code=1";
    }
    
    /**
     * @Title: 北京联通回调
     * @Description: TODO(这里用一句话描述这个方法的作用)
     * @author CXJ
     * @date 2017年4月6日 上午10:10:13
     * @param @param request
     * @param @param response
     * @param @return
     * @return String 返回类型
     * @throws
     */
    public String statusBeijingUniom(HttpServletRequest request, HttpServletResponse response)
    {
        Map<String, Object> paramMap = getMaps(request);
        return "";
    }
    
    /**
     * @Title:statusSanWangTong
     * @Description: 三网通回调查询(这里用一句话描述这个方法的作用)
     * @author CXJ
     * @date 2017年4月28日 上午11:50:25
     * @param @param request
     * @param @param response
     * @param @throws IOException
     * @return void 返回类型
     * @throws
     */
    public String statusSanWangTong(HttpServletRequest request, HttpServletResponse response)
    
    {
        String callbackxml = "";
        Enumeration<String> e = request.getParameterNames();
        while (e.hasMoreElements())
        {
            String s = (String)e.nextElement();
            callbackxml = s + request.getParameter(s);
        }
        Map<String, Object> requestMap = readXml(callbackxml);
        List<Map<String, Object>> itemList = (List<Map<String, Object>>)requestMap.get("item");
        for (Map<String, Object> item : itemList)
        {
            String orderId = item.get("orderId") + "";
            String orderType = item.get("orderType") + "";
            String packCode = item.get("packCode") + "";
            String mobile = item.get("mobile") + "";
            String result = item.get("result") + "";
            String desc = item.get("desc") + "";
            String gateErrorCode = item.get("gateErrorCode") + "";
            
            log.error("三网通回调，获取到的数据为 orderId=" + orderId + "|orderType=" + orderType + "|packCode=" + packCode
                + "|mobile=" + mobile + "|result=" + result + "|desc=" + desc + "|gateErrorCode=" + gateErrorCode);
            if (StringUtils.isEmpty(orderId) || StringUtils.isEmpty(orderType) || StringUtils.isEmpty(packCode)
                || StringUtils.isEmpty(mobile) || StringUtils.isEmpty(result) || StringUtils.isEmpty(desc)
                || StringUtils.isEmpty(gateErrorCode))
            {
                return "<response><result>0001</result><desc>部分参数为空</desc></response>";
            }
            
            Map<String, Object> order = orderDao.selectByOrderId(orderId);// 查询订单
            if (order == null)
            {
                return "<response><result>0001</result><desc>订单不存在</desc></response>";
            }
            if (!"1".equals(order.get("status")))
            {
                log.error("重复回调，订单号为" + orderId);
                return "<response><result>0002</result><desc>重复回调</desc></response>";
            }
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("orderId", orderId);
            // map.put("providerOrderId", orderID);
            
            if (result.equals("0000"))
            {// 充值成功
                map.put("status", 1);
                map.put("resultCode", result + ":" + desc);
            }
            else
            {// 充值失败
                map.put("status", 0);
                map.put("resultCode", gateErrorCode + ":" + desc);
            }
            mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        }
        
        return "<response><result>0000</result><desc></desc></response>";
    }
    
    /**
     * @功能描述： 山东流量平台新接口回调处理
     *
     * @作者：zhangpj @创建时间：2017年7月11日
     * @param request
     * @param response
     * @return
     */
    public String backStatusSdllptUpdate(HttpServletRequest request, HttpServletResponse response)
    {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
        String utcTime = sdf.format(new Date());
        
        String backRequestXml = getRequestContext(request);
        
        log.error("山东流量平台回调开始：[" + backRequestXml + "]");
        StringBuilder sb = new StringBuilder();
        sb.append("<Response>");
        sb.append("<Datetime>").append(utcTime).append("</Datetime>");
        
        if (StringUtils.isEmpty(backRequestXml))
        {
            sb.append("<Code>").append("10001").append("</Code>");
            sb.append("<Message>").append("山东流量平台回调失败,接收到的报文信息为[" + backRequestXml + "]").append("</Message>");
            sb.append("</Response>");
            
            log.error("山东流量平台回调失败,接收到的报文信息为[" + backRequestXml + "]");
            return sb.toString();
        }
        
        // 获取山东流量平台上游回调信息处理结果
        Map<String, String> backRequestMap = getSdllptBackRequestResult(backRequestXml);
        String orderId = backRequestMap.get("serialNum");
        String result = backRequestMap.get("status");
        String desc = backRequestMap.get("description");
        
        Map<String, Object> order = orderDao.selectByOrderId(orderId);// 查询订单
        if (order == null)
        {
            sb.append("<Code>").append("10001").append("</Code>");
            sb.append("<Message>").append("回调失败,未查询到订单号为[" + orderId + "]的订单").append("</Message>");
            sb.append("</Response>");
            
            return sb.toString();
        }
        if (!"1".equals(order.get("status")))
        {
            log.error("重复回调，订单号为" + orderId);
            
            sb.append("<Code>").append("10001").append("</Code>");
            sb.append("<Message>").append("订单号为[" + orderId + "]的订单回调重复").append("</Message>");
            sb.append("</Response>");
            
            return sb.toString();
        }
        
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderId", orderId);
        if (result.equals("3"))
        {
            // 充值成功
            map.put("status", 1);
            map.put("resultCode", result + ":" + desc);
        }
        else if (result.equals("4"))
        {
            // 充值失败
            map.put("status", 0);
            map.put("resultCode", result + ":" + desc);
        }
        else
        {
            // 充值进行中
            map.put("status", 2);
            map.put("resultCode", result + ":" + desc);
        }
        
        mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        
        sb.append("<Code>").append("10000").append("</Code>");
        sb.append("<Message>").append("订单号为[" + orderId + "]的订单回调成功").append("</Message>");
        sb.append("</Response>");
        
        return sb.toString();
    }
    
    @SuppressWarnings("unchecked")
    private static Map<String, Object> readXml(String xml)
    {
        Document doc = null;
        Map<String, Object> map = new HashMap<String, Object>();
        try
        {
            doc = DocumentHelper.parseText(xml); // 将字符串转为XML
            Element rootElt = doc.getRootElement(); // 获取根节点
            Element head = rootElt.element("head");
            List<Element> headList = head.elements();
            
            for (Iterator<Element> iterator = headList.iterator(); iterator.hasNext();)
            {
                Element element = (Element)iterator.next();
                map.put(element.getName(), element.getStringValue());
            }
            Element body = rootElt.element("body");
            List<Element> bodyList = body.elements("item");
            List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
            for (Element iterator : bodyList)
            {
                List<Element> itemList = iterator.elements();
                Map<String, Object> itemMap = new HashMap<String, Object>();
                for (Iterator<Element> iteratorItem = itemList.iterator(); iteratorItem.hasNext();)
                {
                    Element element = (Element)iteratorItem.next();
                    itemMap.put(element.getName(), element.getStringValue());
                }
                list.add(itemMap);
            }
            map.put("item", list);
        }
        catch (DocumentException e)
        {
            e.printStackTrace();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return map;
    }
    
    /**
     * <h5>功能:</h5>获取山东流量平台上游回调信息处理结果
     * 
     * @param xml
     * @return
     * 
     * @author zhangpj @date 2016年8月24日
     */
    private Map<String, String> getSdllptBackRequestResult(String xml)
    {
        Document doc = null;
        Map<String, String> map = new HashMap<String, String>();
        try
        {
            doc = DocumentHelper.parseText(xml); // 将字符串转为XML
            Element rootElt = doc.getRootElement(); // 获取根节点
            Element recordElement = rootElt.element("Record"); // 获取Record枝节点
            
            String serialNum = recordElement.elementTextTrim("SerialNum"); // 获取SerialNum叶子节点
            String systemNum = recordElement.elementTextTrim("SystemNum"); // 获取SystemNum叶子节点
            String mobile = recordElement.elementTextTrim("Mobile"); // 获取SystemNum叶子节点
            String status = recordElement.elementTextTrim("Status"); // 获取SystemNum叶子节点
            String description = recordElement.elementTextTrim("Description"); // 获取SystemNum叶子节点
            String chargeTime = recordElement.elementTextTrim("ChargeTime"); // 获取SystemNum叶子节点
            
            map.put("serialNum", serialNum);// 企业 ID
            map.put("systemNum", systemNum);// 产品编码
            map.put("mobile", mobile);// 充值电话号码
            map.put("status", status);// 充值结果状态,充值结果状态 1:订单已创建 2:已发送充值请求 3:充值成功
                                      // 4:充值失败
            map.put("description", description);// 充值结果描述信息
            map.put("chargeTime", chargeTime);// 充值时间
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return map;
    }
    /**
     * @Title:statusBackWangSen
     * @Description:王森流量充值 TODO(这里用一句话描述这个方法的作用)
     * @author CXJ
     * @date 2017年8月3日 下午3:57:28
     * @param @param request
     * @param @param response
     * @param @return
     * @return String 返回类型
     * @throws
     */
    public String statusBackWangSen(HttpServletRequest request, HttpServletResponse response)
    {
        Map<String, Object> paramMap = getMaps(request);
        String outTradeNo = paramMap.get("OutTradeNo") + "";
        String status = paramMap.get("Status") + "";
        String reportCode = paramMap.get("ReportCode") + "";
        if (StringUtil.isEmpty(outTradeNo) || StringUtil.isEmpty(status) || StringUtil.isEmpty(reportCode))
        {
            log.error("王森回调参数不全");
            return "{\"code\": \"400\", \"msg\": \"参数为空\"}";
        }
        Map<String, Object> order = orderDao.selectByOrderId(outTradeNo);// 查询订单
        if (order == null)
        {
            log.error("王森回调的订单号未找到订单" + outTradeNo);
            return "fail";
        }
        if (!"1".equals(order.get("status")))
        {
            log.error("平台订单号" + outTradeNo + "重复回调不处理");
            return "ok";
        }
//        String providerOrderId = order.get("providerOrderId") + "";
//        
//        if (StringUtil.isEmpty(providerOrderId))
//        {
//            log.error("王森回调的上家订单号未找到订单");
//            return "fail";
//        }
        
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderId", outTradeNo);
        map.put("resultCode", status + ":" + reportCode);
        
        if (status.equals("4"))
        {
            map.put("status", "1");
        }
        else
        {
            map.put("status", "0");
        }
        mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        return "ok";
    }
    
    /**
     * @功能描述：	网信流量回调
     *
     * @作者：zhangpj		@创建时间：2017年8月11日
     * @param request
     * @param response
     * @return
     */
    public String statusBackWangXin(HttpServletRequest request, HttpServletResponse response){
    	String resultStr = getRequestContext(request);
        log.error("网信回调，获取的JSON数据为" + resultStr);
        
        JSONObject jsonObj = JSONObject.parseObject(resultStr);
        String msgId = jsonObj.getString("msgId");
        String err = jsonObj.getString("err");
        
        Map<String, Object> order = orderDao.selectByOrderId(msgId);// 查询订单
        if (order == null){
            log.error("网信回调未找到订单["+msgId+"]");
            return "fail";
        }
        if (!"1".equals(order.get("status"))) {
            log.error("网信回调平台订单号[" + msgId + "]重复回调不处理");
            return "fail";
        }
        
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderId", msgId);
        map.put("resultCode", err);
        
        if ("0".equals(err)) {
        	map.put("status", 1);
            map.put("resultCode", err + ":充值成功");
		} else if ("45".equals(err)){
			map.put("status", 0);
            map.put("resultCode", err + ":充值失败");
		}
        if (map.containsKey("status"))
        {
            mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        }
    	return "0000";
    }
    
    /**
     * @功能描述：	中金云网流量回调
     *
     * @作者：zhangjun		@创建时间：2017年8月31日
     * @param request
     * @param response
     * @return
     */
    public String statusBackZhongJin(HttpServletRequest request, HttpServletResponse response){
    	String resultStr = getRequestContext(request);
        log.error("中金回调，获取的JSON数据为" + resultStr);
        
        JSONObject jsonObj = JSONObject.parseObject(resultStr);
        String msgId = jsonObj.getString("channel_no");
        String code = jsonObj.getString("code");
        
        Map<String, Object> order = orderDao.selectByOrderId(msgId);// 查询订单
        if (order == null){
            log.error("中金回调未找到订单["+msgId+"]");
            return "fail";
        }
        if (!"1".equals(order.get("status"))) {
            log.error("中金回调平台订单号[" + msgId + "]重复回调不处理");
            return "fail";
        }
        
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderId", msgId);
        map.put("resultCode", code);
        
        if ("1111".equals(code)) {
        	map.put("status", 1);
            map.put("resultCode", code + ":充值成功");
		} else if ("9999".equals(code)){
			map.put("status", 0);
            map.put("resultCode", code + ":充值失败");
		}else{
            // 充值进行中
            map.put("status", 2);
            map.put("resultCode", code + ":" +"充值中");
        }
        if (map.containsKey("status"))
        {
            mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        }
    	return "success";
    }
    
    /**
     * @author cxj
     * @param request
     * @param response
     * @return
     */
    public String statusBackNewBoLuoMi(HttpServletRequest request, HttpServletResponse response){
    	String resultStr = getRequestContext(request);
        log.error("波罗蜜新接口回调，获取的JSON数据为" + resultStr);
        
        JSONObject jsonObj = JSONObject.parseObject(resultStr);
        String code = jsonObj.getString("code");
        String msg = jsonObj.getString("msg");
        String orderId = jsonObj.getString("channel_no");
        
        Map<String, Object> order = orderDao.selectByOrderId(orderId);// 查询订单
        if (order == null){
            log.error("波罗蜜新接口回调未找到订单["+orderId+"]");
            return "fail";
        }
        if (!"1".equals(order.get("status"))) {
            log.error("波罗蜜新接口回调平台订单号[" + orderId + "]重复回调不处理");
            return "success";
        }
        
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderId", orderId);
        map.put("resultCode", code+":"+msg);
        
        if ("1111".equals(code)) {
        	map.put("status", 1);
		} else if ("9999".equals(code)){
			map.put("status", 0);
		}
        if (map.containsKey("status"))
        {
            mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        }
    	return "success";
    }
    /**
     * 远特回调
     * 
     * @author zj 2017年3月29日下午3:04:31
     * @param request
     * @param response
     * @return
     */
    public String statusBackForYuanTe(HttpServletRequest request, HttpServletResponse response)
    {
    	String resultStr = getRequestContext(request);
    	JSONObject jsonObj = JSONObject.parseObject(resultStr);
        String outTradeNo = jsonObj.get("outTradeNo") + "";// 平台订单号
        String sysOrderId = jsonObj.get("sysOrderId") + "";// 上家订单号
        String resultCode = jsonObj.get("resultCode") + "";// 充值状态
        String resultDesc = jsonObj.get("resultDesc") + "";
        if (outTradeNo == null || sysOrderId == null || resultCode == null)
        {
            log.error("远特回调参数不全");
            return "{\"code\": \"400\", \"msg\": \"参数为空\"}";
        }
        Map<String, Object> order = orderDao.selectByOrderId(outTradeNo);// 查询订单
        if (order == null)
        {
            log.error("远特回调的订单号未找到订单" + outTradeNo + "||" + sysOrderId);
            return "{\"code\": \"400\", \"msg\": \"参数不正确\"}";
        }
        if (!"1".equals(order.get("status")))
        {
            log.error("平台订单号" + outTradeNo + "重复回调不处理");
            return "{\"code\": \"200\", \"msg\": \"重复回调\"}";
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderId", outTradeNo);
        map.put("providerOrderId", sysOrderId);
        map.put("resultCode", resultCode + ":" + resultDesc);
        if (resultCode.equals("200"))
        {
            map.put("status", "1");
        }
        else
        {
            map.put("status", "0");
        }
        if (map.containsKey("status"))
        {
            mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        }
        return "{\"code\": \"200\", \"msg\": \"success\"}";
    }
    
    public String statusBackHaoBai(HttpServletRequest request, HttpServletResponse response)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> param = getMaps(request);
        String orderId = param.get("customerOrderId") + "";// 上家订单号
        String resStatus = param.get("status") + "";// 订单状态
        Map<String, Object> order = orderDao.selectByOrderId(orderId);// 查询订单
        
        if (order == null)
        {
            log.error("haobai回调的数据查询为空，订单号为" + orderId);
            return "fail";
        }
        String orderid = order.get("orderId") + "";
        String status = order.get("status") + "";
        if (!status.equals("1"))
        {
            log.error("haobai重复回调，订单号为" + orderid);
            return "success";
        }
        map.put("orderId", orderid);
        if (resStatus.equals("success"))
        {// 充值成功
            map.put("status", 1);
        }
        else if (resStatus.equals("fail"))
        {// 充值失败
            map.put("status", 0);
        }
        if (map.containsKey("status"))
        {
            mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        }
        return "success";
    }
    
    /**
     * saiyue
     * @param request
     * @param response
     * @return
     */
    public String statusBackForSaiYue(HttpServletRequest request, HttpServletResponse response)
    {
    	Map<String, Object> param = getMaps(request);

        String code = param.get("code") + "";// 状态编码
        String allocateId = param.get("allocateId") + "";// 上家订单号
        String allocateTime = param.get("allocateTime") + "";//充值时间
        String seqNo = param.get("seqNo") + "";      //平台订单号
        String mobile = param.get("mobile") + "";
        String codeMsg = param.get("codeMsg") + "";  //充值状态

        if (code == null || allocateId == null
                || seqNo == null || mobile == null || codeMsg == null)
        {
            log.error("赛越回调参数不全");
            return "0";
        }
        Map<String, Object> order = orderDao.selectByOrderId(seqNo);// 查询订单
        if (order == null)
        {
            log.error("赛越回调的订单号未找到订单" + seqNo + "||" + allocateId);
            return "0";
        }
        if (!"1".equals(order.get("status")))
        {
            log.error("平台订单号" + seqNo + "重复回调不处理");
            return "1";
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderId", seqNo);
        map.put("allocateId", allocateId);
        map.put("resultCode", code + ":" + codeMsg);
        if (code.equals("0"))
        {
            map.put("status", "1");
        }
        else
        {
            map.put("status", "0");
        }
        if (map.containsKey("status"))
        {
            mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        }
        return "1";

    }
    
    public String statusBackForHuaGu(HttpServletRequest request, HttpServletResponse response)
    {
    	String resultStr = getRequestContext(request);
    	JSONObject jsonObj = JSONObject.parseObject(resultStr);
        String outTradeNo = jsonObj.get("c_id") + "";// 平台订单号
        String sysOrderId = jsonObj.get("order_num") + "";// 上家订单号
        String resultCode = jsonObj.get("status") + "";// 充值状态
        String resultDesc = jsonObj.get("description") + "";
        if (outTradeNo == null || sysOrderId == null || resultCode == null)
        {
            log.error("huagu回调参数不全");
            return "error";
        }
        Map<String, Object> order = orderDao.selectByOrderId(outTradeNo);// 查询订单
        if (order == null)
        {
            log.error("huagu回调的订单号未找到订单" + outTradeNo + "||" + sysOrderId);
            return "error";
        }
        if (!"1".equals(order.get("status")))
        {
            log.error("平台订单号" + outTradeNo + "重复回调不处理");
            return "success";
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderId", outTradeNo);
        map.put("providerOrderId", sysOrderId);
        map.put("resultCode", resultCode + ":" + resultDesc);
        if (resultCode.equals("2"))
        {
            map.put("status", "1");
        }
        else if (resultCode.equals("4"))
        {
            map.put("status", "0");
        }
        if (map.containsKey("status"))
        {
            mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        }
        return "success";
    }
    
    public String statusBackforZhuoYi(HttpServletRequest request, HttpServletResponse response)
    {
    	String resultStr = getRequestContext(request);
    	JSONObject jsonObj = JSONObject.parseObject(resultStr);
        String outTradeNo = jsonObj.get("orderno_ID") + "";// 平台订单号
        String sysOrderId = jsonObj.get("orderID") + "";// 上家订单号
        String resultCode = jsonObj.get("respCode") + "";// 充值状态
        String resultDesc = jsonObj.get("respMsg") + "";
        if (outTradeNo == null || sysOrderId == null || resultCode == null)
        {
            log.error("zhuoyi回调参数不全");
            return "error";
        }
        Map<String, Object> order = orderDao.selectByOrderId(outTradeNo);// 查询订单
        if (order == null)
        {
            log.error("zhuoyi回调的订单号未找到订单" + outTradeNo + "||" + sysOrderId);
            return "error";
        }
        if (!"1".equals(order.get("status")))
        {
            log.error("平台订单号" + outTradeNo + "重复回调不处理");
            return "success";
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderId", outTradeNo);
        map.put("providerOrderId", sysOrderId);
        map.put("resultCode", resultCode + ":" + resultDesc);
        if("0002".equals(resultCode)){
        	map.put("status", "1");
    	}else if("0003".equals(resultCode)){
    		 map.put("status", "0");
    	}
        if (map.containsKey("status"))
        {
            mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        }
        return "success";
    }
    
    public String statusBackforYiGuang(HttpServletRequest request, HttpServletResponse response)
    {
//    	String resultStr = getRequestContext(request);
//    	JSONObject jsonObj = JSONObject.parseObject(resultStr);
//        String outTradeNo = jsonObj.get("order_no") + "";// 平台订单号
//        String resultCode = jsonObj.get("retcode") + "";// 充值状态
//    	String api_userid=request.getParameter("api_userid");
    	String outTradeNo=request.getParameter("order_no");
    	String resultCode=request.getParameter("retcode");
    	log.debug("yiguang回调"+outTradeNo+";----->>>>"+resultCode);

        if (outTradeNo == null  || resultCode == null)
        {
            log.error("yiguang回调参数不全");
            return "error";
        }
        Map<String, Object> order = orderDao.selectByOrderId(outTradeNo);// 查询订单
        if (order == null)
        {
            log.error("yiugang回调的订单号未找到订单" + outTradeNo);
            return "error";
        }
        if (!"1".equals(order.get("status")))
        {
            log.error("平台订单号" + outTradeNo + "重复回调不处理");
            return "success";
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderId", outTradeNo);
        map.put("resultCode", resultCode);
        if("1".equals(resultCode)){
        	map.put("status", "1");
    	}else if("0".equals(resultCode)){
    		 map.put("status", "0");
    	}
        if (map.containsKey("status"))
        {
            mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        }
        return "success";
    }
    
    public String statusBackforJingRunYuan(HttpServletRequest request, HttpServletResponse response)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        String jsonStr = getRequestContext(request);
        if (jsonStr.equals("") || jsonStr == null)
        {
            return "error";
        }
        log.error("jingrunyuan回调，回调参数为" + jsonStr);
        JSONArray jsonArr = JSONObject.parseArray(jsonStr);
        for (int i = 0, size = jsonArr.size(); i < size; i++)
        {
            JSONObject json = jsonArr.getJSONObject(i);
            String upids = json.getString("orderNo");// 上家订单号
            String status = json.getString("status");// 回调状态
            if (upids.equals("") || upids == null || status.equals("") || status == null)
            {
                log.error("jingrunyuan回调部分参数为空");
                return "error";
            }
            Map<String, Object> order = orderDao.selectByProviderOrderId(upids);
            if (order == null)
            {
                log.error("jingrunyuan回调的上家订单号为" + upids + "的订单为空");
                return "error";
            }
            String orderStatus = order.get("status") + "";
            if (!orderStatus.equals("1"))
            {
                log.error("jingrunyuan上家订单号" + upids + "重复回调不处理");
                return "ok";
            }
            String orderId = order.get("orderId") + "";
            map.put("orderId", orderId);
            String message = "";
            if (status.equals("00000"))
            {// 充值成功
                message = "充值成功";
                map.put("status", 1);
            }
            else
            {// 充值失败
                message = "充值失败";
                map.put("status", 0);
            }
            map.put("resultCode", status + ":" + message);
            if (map.containsKey("status"))
            {
                mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
            }
        }
        return "ok";
    }
    
    public String statusBackLangShuo(HttpServletRequest request, HttpServletResponse response)
    {
        Map<String, Object> paramMap = getMaps(request);
        String outTradeNo = paramMap.get("user_order_id") + "";
        String status = paramMap.get("status") + "";
        String reportCode = paramMap.get("errcode") + "";
        if (StringUtil.isEmpty(outTradeNo) || StringUtil.isEmpty(status) || StringUtil.isEmpty(reportCode))
        {
            log.error("langshuo回调参数不全");
            return "fail";
        }
        Map<String, Object> order = orderDao.selectByOrderId(outTradeNo);// 查询订单
        if (order == null)
        {
            log.error("王森回调的订单号未找到订单" + outTradeNo);
            return "fail";
        }
        if (!"1".equals(order.get("status")))
        {
            log.error("平台订单号" + outTradeNo + "重复回调不处理");
            return "ok";
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderId", outTradeNo);
        map.put("resultCode", status + ":" + reportCode);
        
        if (status.equals("4"))
        {
            map.put("status", "1");
        }
        else
        {
            map.put("status", "0");
        }
        if (map.containsKey("status"))
        {
            mqProducer.sendDataToQueue(RabbitMqProducer.Result_QueueKey, SerializeUtil.getStrFromObj(map));
        }
        return "ok";
    }
}
